package demo.practice.leetcode;

import java.util.ArrayList;
import java.util.List;

public class P101 {

    //未解出来，
    public static void main(String[] args) {
        //[1,2,3]
        //[1,2,2,null,3,3]
        //      1
        //    2  2
        //     33
        //[1,2,2,2,null,2]  未通过的情况
        //    1
        //  2   2
        // 2   2
        //
        P101 p101 = new P101();

        TreeNode root = new TreeNode(1);
        root.left= new TreeNode(2);
        root.right=new TreeNode(2);
        root.left.left=new TreeNode(2);
        root.right.left=new TreeNode(2);


        System.out.println(p101.isSymmetric(root));

    }

    public boolean isSymmetric(TreeNode root) {
        nodeBalance(root);

        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) != list.get(list.size() - i - 1))
                return false;
        }

        return true;
    }

    List<Integer> list = new ArrayList<>();

    public void nodeBalance(TreeNode root) {
        if (root == null){
            return ;
        }

        if(root.left!=null)
            nodeBalance(root.left);
        else list.add(-100000);

        list.add(root.val);

        if(root.right!=null)
            nodeBalance(root.right);
        else list.add(-100000);
    }


}
